package com.tvguide;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class Channel extends TabActivity {

		String stadur;
		TabHost tabHost;

		@Override
	    public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			Intent intent = getIntent();
			String channelName = intent.getStringExtra("ChannelName");
			this.setTitle(channelName);
			String Link = intent.getStringExtra("stadur");
			setContentView(R.layout.channel_view);
			TabHost tabHost = getTabHost(); 
			
			try {
	   			Document doc = Jsoup.connect(
	   					"http://www.vodafone.is"+Link).get();
	   			Elements list = doc.select(".days");
	   			Elements days = list.select("a");
	   			
	   			for (Element item:days){
		   			Element day = item.select("a").first();
		   			String href= item.attr("href");
		   			String dayOfWeek = day.text().toString();
		   			int maxLength = 5;
		   			if(dayOfWeek.length() > maxLength)
		   				dayOfWeek =  dayOfWeek.substring(0,3);
		   			Intent intentDagskra = new Intent().setClass(this, ChannelActivity.class);
		   			intentDagskra.putExtra("href", href);
		   			TabSpec tabSpecDays = tabHost
						.newTabSpec(href)
						.setIndicator(dayOfWeek)
						.setContent(intentDagskra);
					tabHost.addTab(tabSpecDays);
	   			}
			}
			
			catch (Exception e) {
	   			e.printStackTrace();
	   			Log.d("villa virkar ekki","villa virkar ekki - Channel");
	   		}
			
			tabHost.setCurrentTab(0);		   		
	    }
	}  

